<%--
  Created by IntelliJ IDEA.
  User: 浮槎北冥海茫茫
  Date: 2021/7/8
  Time: 21:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8"  language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<!-- 网页使用的语言 -->
<html lang="zh-CN">
<head>
    <!-- 指定字符集 -->
    <meta charset="utf-8">
    <!-- 使用Edge最新的浏览器的渲染方式 -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- viewport视口：网页可以根据设置的宽度自动进行适配，在浏览器的内部虚拟一个容器，容器的宽度与设备的宽度相同。
    width: 默认宽度与设备的宽度相同
    initial-scale: 初始的缩放比，为1:1 -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>用户信息管理系统</title>

    <!-- 1. 导入CSS的全局样式 -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- 2. jQuery导入，建议使用1.9以上的版本 -->
    <script src="js/jquery-2.1.0.min.js"></script>
    <!-- 3. 导入bootstrap的js文件 -->
    <script src="js/bootstrap.min.js"></script>
    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>
    <script>
        function  deleteUser(id) {

            if(confirm("你确定要删除吗？")){

                location.href="${pageContext.request.contextPath}/delUserServlet?id="+id;
            }
            window.onload = function(){
                //给删除选中按钮添加单击事件
                document.getElementById("delSelectedUser").onclick = function(){
                    if(confirm("您确定要删除选中条目吗？")){

                        var flag = false;
                        //判断是否有选中条目
                        var cbs = document.getElementsByName("uid");
                        for (var i = 0; i < cbs.length; i++) {
                            if(cbs[i].checked){
                                //有一个条目选中了
                                flag = true;
                                break;
                            }
                        }

                        if(flag){//有条目被选中
                            //表单提交
                            document.getElementById("form").submit();
                        }

                    }

                }
                //1.获取第一个cb
                document.getElementById("firstCb").onclick = function(){
                    //2.获取下边列表中所有的cb
                    var cbs = document.getElementsByName("uid");
                    //3.遍历
                    for (var i = 0; i < cbs.length; i++) {
                        //4.设置这些cbs[i]的checked状态 = firstCb.checked
                        cbs[i].checked = this.checked;

                    }

                }


            }

        }
    </script>
</head>
<body>
<div class="container">
    <h3 style="text-align: center">管理员页面</h3>
    <div style="float: left">
        <form class="form-inline" action="${pageContext.request.contextPath}/findUserByPageServlet" method="post">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" class="form-control" name="username" value="${condition.username[0]}" id="username" placeholder="">
            </div>
            <div class="form-group">
                <label for="remark">地位</label>
                <input type="text" class="form-control" name="remark" value="${condition.remark[0]}" id="remark" placeholder="">
            </div>

            <button type="submit" class="btn btn-default">查询</button>
        </form>
    </div>
    <div style="float: right;margin: 5px">
        <a class="btn btn-primary" href="${pageContext.request.contextPath}/add.jsp">添加用户</a>
        <%--<a class="btn btn-primary" href="javascript:void(0);" id="delSelectedUser">删除选中</a>--%>
    </div>
    <div style="float: right;margin: 5px">
        <a class="btn btn-primary" href="${pageContext.request.contextPath}/hello1.jsp">返回用户首页</a>
        <%--<a class="btn btn-primary" href="javascript:void(0);" id="delSelectedUser">删除选中</a>--%>
    </div>
    <form action="${pageContext.request.contextPath}/delSelectedUserServlet" method="post">
        <table id="form" border="1" class="table table-bordered table-hover">
            <tr class="success">
                <%--           --%>
                <%--<th><input type="checkbox" id="firstCb"></th>--%>
                <th>id</th>
                <th>姓名</th>
                <th>密码</th>
                <th>地位</th>
                <th>权限</th>
                <th>操作</th>
            </tr>
            <%--这里要注意是从页面信息的list集合中获取参数--%>
            <c:forEach items="${pb.list}" var="user" varStatus="s">
                <tr >
                        <%-- <th><input type="checkbox" name="uid" value="${user.id}" ></th>--%>
                    <th>${user.id}</th>
                    <th>${user.username}</th>
                    <th>${user.password}</th>
                    <th>${user.remark}</th>
                    <th>${user.position}</th>
                    <td><a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/findUserServlet?id=${user.id}">修改</a>&nbsp;
                        <a class="btn btn-default btn-sm" href="javascript:deleteUser(${user.id});">删除</a></td>
                </tr>
            </c:forEach>
        </table>
    </form>
    <div>
        <nav aria-label="Page navigation">
            <ul class="pagination">
                <c:if test="${pb.currentPage==1}">
                <li class="disabled">
                    </c:if>
                    <c:if test="${pb.currentPage!=1}">
                <li>
                    </c:if>

                    <a href="${pageContext.request.contextPath}/findUserByPageServlet?currentPage=${pb.currentPage-1}&rows=5&username=${condition.username[0]}&remark=${condition.remark[0]}" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
                <c:forEach begin="1" end="${pb.totalPage}" var="i">
                    <%--               <li><a href="${pageContext.request.contextPath}/findUserByPageServlet?currentPage=${i}&rows=5">${i}</a></li>--%>
                    <c:if test="${pb.currentPage==i}">
                        <li class="active"><a href="${pageContext.request.contextPath}/findUserByPageServlet?currentPage=${i}&rows=5"&username=${condition.username[0]}&remark=${condition.remark[0]}>${i}</a></li>
                    </c:if>
                    <c:if test="${pb.currentPage!=i}">
                        <li ><a href="${pageContext.request.contextPath}/findUserByPageServlet?currentPage=${i}&rows=5&username=${condition.username[0]}&remark=${condition.remark[0]}">${i}</a></li>
                    </c:if>
                </c:forEach>
                <c:if test="${pb.currentPage>=pb.totalPage}">
                    <li class="disabled">

                        <a href="${pageContext.request.contextPath}/findUserByPageServlet?currentPage=${pb.currentPage}&rows=5&username=${condition.username[0]}&remark=${condition.remark[0]}" aria-label="Next">
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                    </li>
                </c:if>
                <c:if test="${pb.currentPage<pb.totalPage}">
                    <li>

                        <a href="${pageContext.request.contextPath}/findUserByPageServlet?currentPage=${pb.currentPage+1}&rows=5&username=${condition.username[0]}&remark=${condition.remark[0]}" aria-label="Next">
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                    </li>
                </c:if>

                <span style="font-size: 25px;margin-left: 5px">
                   共${pb.totalCount}条记录，${pb.totalPage}页
               </span>
            </ul>
        </nav>
    </div>
</div>
</body>
</html>

